<?PHP
// GRRLIB GFX convertor (png to C array)
// This file is part of the GRRLIB package for WII
// info : http://wiibrew.org/index.php?title=Homebrew_apps/GRRLIB

$img = $argv[1];

$im = ImageCreateFromPng($img.".png");
$img_high = imagesy($im); 
$img_width = imagesx($im);

$file = fopen($img.".h", "w+");


fwrite($file, "// Bitmap file from ".$img.".png\n");
fwrite($file, "// Converted With moulinette included in GRRLIB package\n\n");
fwrite($file, "const int ".$img."_high=".$img_high.";\n"); 
fwrite($file, "const int ".$img."_width=".$img_width.";\n\n"); 
fwrite($file, "const u16 ".$img."_img[]={\n"); 

for($y=0;$y<$img_high;$y++){
  for($x=0;$x<$img_width;$x++){
    $cpt++;
    $rgb = ImageColorAt($im, $x, $y);
    $r = intval(((($rgb >> 16) & 0xFF)*31)/255);
    $g = intval(((($rgb >> 8) & 0xFF)*63)/255);
    $b = intval(((($rgb) & 0xFF)*31)/255);


$toto=((($r)<<6)|$g);
$plop=((($toto)<<5)|$b);

    $result = base_convert($plop,10,16);
    fwrite($file,"0x".$result);
    if($cpt!=($img_high*$img_width))
    fwrite($file,",");
  }
  fwrite($file,"\n");
}
fwrite($file,"};\n\n");
fclose($file);

?>
